<template>
	<view>
		<view class="">
			<van-nav-bar title="结算商品" left-text="返回" left-arrow @click-left="onClickLeft" />
		</view>
		<view class="price" v-for="(a, index) in orderlist" :key="index">
			{{ a.orderPrice }}
		</view>
		<button class="paybtn" @click="zfb">支付宝支付</button>
	</view>
</template>

<script>
	import request from '../../com/request.js'
	export default {
		data() {
			return {
				orderId: "",
				orderlist: [],
				commodityId: uni.getStorageSync('hx220408commodityId')
			}
		},
		methods: {
			zfb() {
				this.aaa = this.orderId.id;
				this.orderPrice = this.orderlist[0].orderPrice;
				this.loading = true;
				let dataobj = {
					orderId: this.aaa, //随机生成唯一的就行了这个 自己找吧
					orderPrice: this.orderPrice,
				};

				let params = dataobj
				console.log(this.aaa, 68686);
				console.log(params, 35);
				request({
					method: "POST",
					url: "pay",
					data: params,
				}).then((res) => {
					console.log(res[1].data.code);
					// window.open(res.data.code);
					uni.setStorageSync('zfbSrc', res[1].data.code)
					// 跳转页
					uni.redirectTo({
						url: '/pages/lz/lz'
					})
				});
			},
			onClickLeft() {
				// this.$Toast('返回');
				uni.navigateBack({
						delta:1,//返回层数，2则上上页
					})
			},
			handsome() {
				var that = this
				request({
					url: 'api/orderTable/tallyorder',
					data: {
						orderId: this.orderId.id,
						category: this.orderId.type,
					},
					method: "GET",
					dataType: 'json',
					success: function(resp) {
						console.log(resp.data.data, 8888)
						that.orderlist = resp.data.data;
					}
				})
			}
		},
		onLoad() {
			this.orderId = JSON.parse(uni.getStorageSync("orderId"));
			this.handsome()
			this.socket.on('paysuccess', (data) => {
				
				console.log(data)
				if (data.orderid == this.aaa) {
					if(this.orderId.type==3){
						console.log('支付成功:77')
						request({
							url: "api/deposTabel/cashpledge",
							methods: "GET", //type
							data: {
								orderId: this.orderId.id,
							},
						}).then((resp)=>{
							console.log(resp)
						}).catch((err)=>{
							console.log(resp)
						})
					}else{
						
					
					request({
						url: "api/orderTable/zfsucceed",
						methods: "GET", //type
						data: {
							orderId: this.orderId.id,
						},
					})
					.then((resp) => {
						console.log(resp);
						request({
							url: 'api/commodityTable/comsucceed',
							methods: "GET",
							data: {
								commodityId: this.commodityId
							}
						}).then(resp => {
							console.log(resp);
							console.log(this.commodityId, 4543654645);
						}).catch(err => {
							console.log(err);
						})
					})
					.catch((err) => {
						console.log(err);
					});
				}
				}
			})

		}

	}
</script>

<style>
	.paying {}

	.price {
		width: 200rpx;
		height: 200rpx;
		margin-top: 100rpx;
		background-color: antiquewhite;
		border-radius: 10px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 30px;
		margin: auto;
	}

	.paybtn {
		width: 350rpx;
		height: 60rpx;
		margin-top: 100px;
		border: 0;
		background: gold;
		border-radius: 10px;
		font-size: 30rpx;
	}
</style>

